package checkers;

import java.util.ArrayList;
import java.util.List;

public class CheckersMovement {

    private List<CheckersOperation> movementsList;

    public CheckersMovement(List<CheckersOperation> movementsList) {
        this.movementsList = movementsList;
    }

    public List<CheckersOperation> getMovementsList() {
        return movementsList;
    }

    public void setMovementsList(List<CheckersOperation> movementsList) {
        this.movementsList = movementsList;
    }

    public CheckersMovement clone() {
        List<CheckersOperation> operationsList = new ArrayList<CheckersOperation>();
        for (CheckersOperation co : this.movementsList) {
            operationsList.add(co.clone());
        }
        return new CheckersMovement(operationsList);
    }

    public CheckersOperation getLast(byte operation) {
        for (int i = this.movementsList.size() - 1; i >= 0; i--) {
            if (movementsList.get(i).operation == operation) {
                return movementsList.get(i);
            }
        }
        return null;
    }

    public CheckersOperation getFirst(byte operation) {
        for (int i = 0; i < this.movementsList.size(); i++) {
            if (movementsList.get(i).operation == operation) {
                return movementsList.get(i);
            }
        }
        return null;
    }

    public short countOperations(byte operation) {
        short i = 0;
        for (CheckersOperation co : movementsList) {
            if (co.operation == operation) {
                i++;
            }
        }
        return i;
    }
}
